#include "PhysicWorld.hpp"
#include <cassert>



PhysicWorld::PhysicWorld():
m_world(NULL)
{
}
PhysicWorld::~PhysicWorld()
{
    destroyWorld();
}   

PhysicWorld& PhysicWorld::instance()
{
    static PhysicWorld pw;
    return pw;
}

void PhysicWorld::createWorld()
{
    destroyWorld();
    m_world = new b2World(b2Vec2(0,-9.81f),true);
}

void PhysicWorld::destroyWorld()
{
    if(m_world)
        delete m_world;
    
    m_world = NULL;
}

b2World* PhysicWorld::world()
{
    assert(m_world != NULL);
    
    return m_world;
}

void PhysicWorld::update(const float dt)
{
    assert(m_world != NULL);
    
    m_world->ClearForces();
    m_world->Step(dt,10,5);
}
